package leetcode;

/**
 * Created with IntelliJ IDEA.
 * User: Ghost
 * Date: 14-6-8
 * Time: 下午9:26
 * To change this template use File | Settings | File Templates.
 */
public class Best_Time_to_Buy_and_Sell_Stock_II {
    public static int maxProfit(int[] prices) {

        if(prices == null)
            return 0;
        int maxProfit = 0;
        for(int i=0,j=1;i<prices.length && j<prices.length;i++,j++){
            int tmp = prices[j] - prices[i];
            if(tmp>0){
                maxProfit+=tmp;
            }
        }
        return maxProfit;
    }
    public static void main(String[] args){
        int[] prices = {8,5,6,7,2,1};
        System.out.println(maxProfit(prices));
    }
}
